package db;

import java.sql.*;

import javax.sql.*;

public class DbConnect {
	private static String user;
	private static String pass;
	private static String dbName;
	private static String dbHost;
	private static String dbUrl;
	private static String dbClass = "com.mysql.jdbc.Driver";
	private static Statement stmt;
	private static Connection con;
	
	public DbConnect()
	{
			user = new String("mihai");
			pass = new String("ssZY99b9K2MCDHCs");
			dbName = new String("mihai");
			dbHost = new String("doraz.ro");
			dbUrl = new String("jdbc:mysql://doraz.ro/mihai");
	}
	
	public DbConnect(String chost, String cdbName, String cuser, String cpass)
	{
		user = new String(cuser);
		pass = new String(cpass);
		dbHost = new String(chost);
		dbName = new String(cdbName);
		dbUrl = new String("jdbc:mysql://" + dbHost + "/" + dbName);
	}
	
	public static boolean connect()
	{
		try {

			Class.forName(dbClass);
			System.out.println(dbUrl);
			con = DriverManager.getConnection ("jdbc:mysql://doraz.ro/mihai","mihai","ssZY99b9K2MCDHCs");
			stmt = con.createStatement();
			return true;
		} //end try

		catch(ClassNotFoundException e) {
			e.printStackTrace();
		}

		catch(SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public static boolean disconnect()
	{
		try {

			con.close();
			return true;
		} //end try

		catch(SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public static ResultSet query(String queryString) throws SQLException		//se foloseste pentru cereri SELECT
	{
		return stmt.executeQuery(queryString);
	}
	
	public static int IUDQuery(String queryString) throws SQLException		//se foloseste pentru INSERT UPDATE si DELETE (data manipulation)
	{
		return stmt.executeUpdate(queryString);
	}
}